package com.fowo.api.model.sales.withdraw;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fowo.api.entity.SalesWithdraw;
import com.fowo.api.mapper.SalesWithdrawMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
@Slf4j
@DS("ds24")
public class SalesWithdrawZuofeiImpl extends ServiceImpl<SalesWithdrawMapper, SalesWithdraw> implements SalesWithdrawZuofeiAction{

    @Resource
    SalesWithdrawMapper salesWithdrawMapper;

    @Override
    public void run(Long id) throws Exception {
        SalesWithdraw salesWithdraw = salesWithdrawMapper
                .selectOne(Wrappers.lambdaQuery(SalesWithdraw.class).
                        eq(SalesWithdraw::getStatus, "2")
                        .eq(SalesWithdraw::getId, id));
        if(salesWithdraw!=null){
            throw new Exception("此单已作废");
        }else {
            new LambdaUpdateChainWrapper<>(baseMapper)
                    .set(SalesWithdraw::getStatus, "2")
                    .eq(SalesWithdraw::getId, id)
                    .update();
        }
    }
}
